package org.yinxue.swing.im.domain.event;

import com.google.common.eventbus.EventBus;

import java.util.EventObject;
import java.util.List;

public class EventPublisher {

    private EventBus eventBus;
    private static final EventPublisher EVENT_PUBLISHER = new EventPublisher();

    public static EventPublisher instance() {
        return EVENT_PUBLISHER;
    }

    public EventPublisher() {
        eventBus = new EventBus();
    }

    public void publish(EventObject event) {
        eventBus.post(event);
    }

    public void publish(List<EventObject> events) {
        events.stream().forEach(eventBus::post);
    }

    public void register(Object sub){
        eventBus.register(sub);
    }
}
